package com.ksana.bean;

import java.util.ArrayList;
import java.util.List;

public class PropertyValues {
    private List<PropertyValue> propertyValues;

    public PropertyValues() {
        this(null);
    }

    public PropertyValues(List<PropertyValue> propertyValues) {
        this.propertyValues = this.propertyValues == null ? new ArrayList<>() : propertyValues;
    }

    public List<PropertyValue> getPropertyValues() {
        return propertyValues;
    }

    public PropertyValues addPropertyValue(PropertyValue pv) {
        for (PropertyValue propertyValue : propertyValues) {
            if (propertyValue.getName().equals(pv.getName())) {
                propertyValue.setValue(pv.getValue());
                return this;
            }
        }

        propertyValues.add(pv);
        return this;
    }

    public void removePropertyValue(String name) {
        for (PropertyValue propertyValue : propertyValues) {
            if (propertyValue.getName().equals(name)) {
                propertyValues.remove(propertyValue);
            }
        }
    }
}
